package com.canic.dkd.authorization.staff.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.canic.dkd.authorization.staff.entity.SysPermission;
import com.canic.dkd.authorization.staff.entity.SysRole;
import com.canic.dkd.authorization.staff.entity.SysUser;
import com.canic.dkd.authorization.staff.mapper.SysUserMapper;
import com.canic.dkd.authorization.staff.service.SysUserService;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户
 * @author ZC
 * @since 2019-05-02
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Override
    public List<SysPermission> getPermissionListByUserId(String userId) {
        List<SysPermission> list = baseMapper.getPermissionListByUserId(userId);
        if(CollectionUtils.isEmpty(list)){
            return Lists.newArrayList();
        }
        return list;
    }

    @Override
    public List<SysRole> getRoleListByUserId(String userId) {
        List<SysRole> list = baseMapper.getRoleListByUserId(userId);
        if(CollectionUtils.isEmpty(list)){
            return Lists.newArrayList();
        }
        return list;
    }

    @Override
    public SysUser getUserByName(String userName) {
        Map<String, Object> queryMap = new HashMap();
        queryMap.put("name", userName);
        List<SysUser> list = baseMapper.selectByMap(queryMap);
        if(CollectionUtils.isEmpty(list)){
            return null;
        }
        return list.get(0);
    }
}
